package br.com.locasis.conversores;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import br.com.locasis.utilitarios.UtilString;

@org.jboss.seam.annotations.faces.Converter(id="conversorUpperCase")
public class ConversorUpperCase implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component, String valorCampo){
	   Object nome = null;
	   if(valorCampo != null) {
           if(!UtilString.isStringVazia(valorCampo)){
               nome = desmascara(valorCampo);
           }
	   }
	   return nome;
    }

    public String getAsString(FacesContext context, UIComponent component, Object objCampo){
       String nome = null;
       if(objCampo != null) {
           if(!UtilString.isStringVazia(objCampo.toString())){
               nome = mascara(objCampo);
           }
       }
       return nome;
    }
    
    public static Object desmascara(String nome) {
       return nome.toUpperCase();
    }

    public static String mascara(Object nome) {
    	return nome.toString().toUpperCase();
    }

}
